package com.hq.service;

import com.hq.bean.Canteen;
import com.hq.bean.User;
import com.hq.dao.CanteenDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CanteenServiceImpl implements CanteenService{
    @Resource
    private CanteenDao canteenDao;
    @Override
    public List list(Map map) {
        return canteenDao.list(map);
    }

    @Override
    public List cityList(Integer pid) {
        return canteenDao.cityList(pid);
    }

    @Override
    public int add(Canteen canteen, Integer[] fids) {
        //添加主表
        int i = canteenDao.add(canteen);
        //添加中间
        if (fids!=null && fids.length>0){
            Map map = new HashMap();
            map.put("cid",canteen.getCid());
            map.put("fids",fids);
            canteenDao.addzhong(map);
        }
        return i;
    }

    @Override
    public int del(Integer cid) {
        //删除中间
        canteenDao.delzhong(cid);
        //删除主表
        int i = canteenDao.del(cid);

        return i;
    }

    @Override
    public int upd(Canteen canteen, Integer[] fids) {
        //修改主表
        int i = canteenDao.upd(canteen);
        //删除中间表
        canteenDao.delzhong(canteen.getCid());
        //添加中间
        if (fids!=null && fids.length>0){
            Map map = new HashMap();
            map.put("cid",canteen.getCid());
            map.put("fids",fids);
            canteenDao.addzhong(map);
        }
        return i;
    }

    @Override
    public Map getInfoByCid(Integer cid) {
        return canteenDao.getInfoByCid(cid);
    }

    @Override
    public User login(User user) {
        return canteenDao.login(user);
    }
}
